package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.ProcessSheetDto;
import com.pureut.production.domain.vo.MaterialInfoVo;
import com.pureut.production.domain.vo.ProcessSheetVo;
import com.pureut.production.domain.vo.PublicProcessVo;
import com.pureut.production.service.ProcessSheetService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工艺卡控制层
 * @author: CM
 * @date: 2023/2/17  13:43
 */
@RestController
@RequestMapping("/processSheet")
public class ProcessSheetController extends BaseController {

    @Resource
    private ProcessSheetService processSheetService;

    /**
     * 新增工艺卡
     */
    @RequiresPermissions("productionTube:processmage:processcard:add")
    @Log(title = "新增工艺卡", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody ProcessSheetVo processSheetVo) throws Exception {
        return toAjax(processSheetService.add(processSheetVo));
    }

    /**
     * 修改工艺卡
     */
    @RequiresPermissions("productionTube:processmage:processcard:edit")
    @Log(title = "修改工艺卡", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody ProcessSheetVo processSheetVo) {
        return toAjax(processSheetService.edit(processSheetVo));
    }

    /**
     * 删除工艺卡
     */
    @RequiresPermissions("productionTube:processmage:processcard:remove")
    @Log(title = "删除工艺卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable("ids") String ids) {
        return toAjax(processSheetService.remove(ids));
    }

    /**
     * 查看工艺卡
     */
    @RequiresPermissions("productionTube:processmage:processcard:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) {
        return AjaxResult.success(processSheetService.getView(id));
    }

    /**
     * 查看工艺卡列表
     * @param processSheetVo
     * @return
     */
    @RequiresPermissions("productionTube:processmage:processcard:list")
    @GetMapping("/list")
    public TableDataInfo list(ProcessSheetVo processSheetVo)
    {
        startPage();
        List<ProcessSheetDto> list = processSheetService.selectSheetList(processSheetVo);
        return getDataTable(list);
    }

    /**
     * 配置工艺卡参数
     */
    @Log(title = "修改工艺卡配置参数", businessType = BusinessType.UPDATE)
    @PostMapping("/editTemplete")
    public AjaxResult editTemplete(@Validated @RequestBody PublicProcessVo publicProcessVo) {
        return toAjax(processSheetService.editTemplete(publicProcessVo));
    }

    /**
     * 根据生产阶别找对应的线别
     */
    @GetMapping("/getLine")
    public AjaxResult getLine(String productionLevel) {
        return AjaxResult.success(processSheetService.getLine(productionLevel));
    }

    /**
     * 根据生产阶别展示工艺流程
     */
    @GetMapping("/getProcess")
    public AjaxResult getProcess(String productionLevel) {
        return AjaxResult.success(processSheetService.getProcess(productionLevel));
    }

    /**
     * 查询物料名称,物料规格,物料编码
     */
    @GetMapping("/getMaterialInfo")
    public AjaxResult getMaterialInfo(MaterialInfoVo materialInfoVo) {
        return AjaxResult.success(processSheetService.getMaterialInfo(materialInfoVo));
    }


}
